#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：employment_class 
@File    ：05_login_test.py
@IDE     ：PyCharm 
@Author  ：小邓的烂笔头
@Date    ：2021/10/30 下午4:09 
"""
from pymysql import *
import redis
from hashlib import sha1


class RedisHelper(object):
    def __init__(self, host, port):
        self.__redis = redis.StrictRedis(host, port)

    def set(self, key, value):
        self.__redis.set(key, value)

    def get(self, key):
        return self.__redis.get(key)


class MySqlHelper(object):
    def __init__(self):
        self.connect = connect(
            host='localhost',
            port=3306,
            user='root',
            password='123456',
            db='base'
        )
        self.cursorl = self.connect.cursor()

    def close(self):
        self.cursorl.close()
        self.connect.close()

    def cud(self, sql, params):
        try:
            self.cursorl.execute(sql, params)
            result = self.cursorl.fetchall()
            self.connect.commit()
            return result
        except Exception as e:
            print(e)
        finally:
            self.close()

    def one(self,sql,params=[]):
        try:
            pass
        except Exception as e:
            print(e)


def sha_pwd(passwd):
    s = sha1()
    s.update(passwd)
    passwd = s.hexdigest()
    return passwd


